package com.zzp.zjs_bos.web.action;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.apache.xmlbeans.impl.xb.xsdschema.RestrictionDocument.Restriction;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;


import com.zzp.zjs_bos.domain.Staff;
import com.zzp.zjs_bos.utils.PageBean;
import com.zzp.zjs_bos.web.action.base.BaseAction;


@Controller
@Scope("prototype")
public class StaffAction extends BaseAction<Staff>{
	
	public String save(){
		if(model.getHaspda() == null){
			model.setHaspda("0");
		}
		staffService.save(model);
		return "list";
	}
	
	private int page;
	private int rows;
	
	
	public String pageQuery() throws IOException{
		staffService.pageQuery(pageBean,model);
		String[] excludes = new String[]{"decidedzones"};
		this.writePageBean2Json(pageBean, excludes);
		return NONE;
	}
	
	private String ids;
	public void setIds(String ids) {
		this.ids = ids;
	}
	
	public String delete(){
		staffService.delete(ids);
		return "list";
	}
	
	public String edit(){
		Staff staff = staffService.findById(model.getId());
		staff.setName(model.getName());
		staff.setTelephone(model.getTelephone());
		staff.setStation(model.getStation());
		staff.setStandard(model.getStandard());
		if(model.getHaspda() == null){
			model.setHaspda("0");
		}
		staffService.update(staff);
		return "list";
	}
	
	public String recover(){
		staffService.recover(ids);
		
		return "list";
	}
	
	public String findSome(){
		DetachedCriteria dc = DetachedCriteria.forClass(Staff.class);
		dc.add(Restrictions.eq("deltag", "0"));
		dc.add(Restrictions.isEmpty("decidedzones"));
		List<Staff> list = staffService.findSome(dc);
		String[] excludes = new String[]{"telephone","haspda","deltag","station","standard","decidedzones"};
		this.writeList2Json(list, excludes);
		return NONE;
	}
	
	
	
}
